package com.inhgroup.flashcards.data;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;
import org.junit.Test;

/**
 * Tests the CardList class.
 * 
 * @author Branden Ogata
 *
 */

public class TestCardList
{
  /**
   * Tests the methods in the CardList class.
   * 
   */
  
  @Test
  public void test()
  {
    List<Card> cards = new LinkedList<Card>(Arrays.asList(new Card("chi", "ち"),
                                                          new Card("ha", "は"),
                                                          new Card("ya", "や")));
    CardList list = new CardList("English-Japanese Test", cards, "English", "Japanese");
    
    assertEquals("Title should set correctly", "English-Japanese Test", list.getTitle());
    assertEquals("Front language should set correctly", "English", list.getFrontLanguage());
    assertEquals("Back language should set correctly", "Japanese", list.getBackLanguage());
    
    assertEquals("Card at index 0 should be correct", new Card("chi", "ち"), list.getCard(0));
    assertEquals("Card at index 1 should be correct", new Card("ha", "は"), list.getCard(1));
    assertEquals("Card at index 2 should be correct", new Card("ya", "や"), list.getCard(2));
    
    try
    {
      list.getCard(-1);
      fail();
    }
    catch (IndexOutOfBoundsException e)
    {
      assertTrue("Should throw exception for illegal index -1", 
                 e.getMessage().contains("-1"));
    }
    
    try
    {
      list.getCard(3);
      fail();
    }
    catch (IndexOutOfBoundsException e)
    {
      assertTrue("Should throw exception for illegal index 3", 
                 e.getMessage().contains("3"));
    }
  }
}